<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      background-color: red;
      transition: all .4s;
    }

    .active {
      transform: translateX(300px);
    }
  </style>
</head>

<body>
  <div class="box"></div>
  <script>
    /* 动画的产生必须是一种状态到另一种状态 */
    /* 浏览器渲染完毕 => 才会开启下一个宏任务 */
    const oBox = document.querySelector('.box')
    setTimeout(() => {
      oBox.classList.add('active')
    });
  </script>
</body>

</html>